class control(object):
    def signalIn(self, oppCode, function):
        self.mfhilo = 0 #0=none, 1=mfhi, 2=mflo, used for determining alusource
        if (oppCode == 0b000000): # rtype
            self.regDst = 1
            self.aluSrc = 0
            self.memToReg = 0
            self.regWrite = 1
            self.memRead = 0
            self.memWrite = 0
            self.branch = 0
            self.branchne = 0
            self.jump = 0
            self.exception = 0
            self.syscall = 0
            self.ERET = 0
            self.upperImmediate = 0
            self.mduOp = 0
            if (function == 0b100000): #add
                self.aluOp = 0b0010
                self.shift = 0
            elif (function == 0b100001): #addu
                self.aluOp = 0b0011
                self.shift = 0
            elif (function == 0b100010): #sub
                self.aluOp = 0b0110
                self.shift = 0
            elif (function == 0b100011): #subu
                self.aluOp = 0b1011
                self.shift = 0
            elif (function == 0b100100): #and
                self.aluOp = 0b0000
                self.shift = 0
            elif (function == 0b100101): #or
                self.aluOp = 0b0001
                self.shift = 0
            elif (function == 0b101010): #slt
                self.aluOp = 0b0111
                self.shift = 0
            elif (function == 0b000000): #sll
                self.aluOp = 0b1000
                self.shift = 1
            elif (function == 0b000010): #srl
                self.aluOp = 0b1001
                self.shift = 1
            elif (function == 0b000011): #sra
                self.aluOp = 0b1111
                self.shift = 1
            elif (function == 0b001100): #syscall
                self.aluOp = 0b0000
                self.exception = 1
                self.syscall = 1
            elif (function == 0b011000): #mult
                self.mduOp = 0b01           #I'm thinking 1 for mult, 2 for div, 3/4 for unsigned when we get to that.
                self.aluOp = 0b0000
                self.regDst = 0
                self.regWrite = 0
                self.shift = 0
            elif (function == 0b011010): #div
                self.mduOp = 0b10
                self.aluOp = 0b0000
                self.regDst = 0  
                self.regWrite = 0       
                self.shift = 0    
            elif (function == 0b010000): #mfhi
                self.aluOp = 0b0001
                self.shift = 0
                self.mfhilo = 1
            elif (function == 0b010010): #mfhi
                self.aluOp = 0b0001
                self.shift = 0 
                self.mfhilo = 2
            else:
                self.aluOp = 0b0000
                self.shift = 0
                
        elif (oppCode == 0b000010): #jump (j)
            self.regDst = 0
            self.aluSrc = 0
            self.memToReg = 0
            self.regWrite = 0
            self.memRead = 0
            self.memWrite = 0
            self.branch = 0
            self.branchne = 0
            self.jump = 1
            self.shift = 0
            self.exception = 0
            self.syscall = 0
            self.ERET = 0
            self.aluOp = 0b0000
            self.upperImmediate = 0

        elif (oppCode == 0b001000): #addi
            self.regDst = 0
            self.aluSrc = 1
            self.memToReg = 0
            self.regWrite = 1
            self.memRead = 0
            self.memWrite = 0
            self.branch = 0
            self.branchne = 0
            self.jump = 0
            self.shift = 0
            self.exception = 0
            self.syscall = 0
            self.ERET = 0
            self.aluOp = 0b0010
            self.upperImmediate = 0
            
        elif (oppCode == 0b001111): #lui
            self.regDst = 0
            self.aluSrc = 1
            self.memToReg = 0
            self.regWrite = 1
            self.memRead = 0
            self.memWrite = 0
            self.branch = 0
            self.branchne = 0
            self.jump = 0
            self.shift = 0
            self.exception = 0
            self.syscall = 0
            self.ERET = 0
            self.aluOp = 0b0010
            self.upperImmediate = 1

        elif (oppCode == 0b001100): #andi
            self.regDst = 0
            self.aluSrc = 1
            self.memToReg = 0
            self.regWrite = 1
            self.memRead = 0
            self.memWrite = 0
            self.branch = 0
            self.branchne = 0
            self.jump = 0
            self.shift = 0
            self.exception = 0
            self.syscall = 0
            self.ERET = 0
            self.aluOp = 0b0000
            self.upperImmediate = 0

        elif (oppCode == 0b001101): #ori
            self.regDst = 0
            self.aluSrc = 1
            self.memToReg = 0
            self.regWrite = 1
            self.memRead = 0
            self.memWrite = 0
            self.branch = 0
            self.branchne = 0
            self.jump = 0
            self.shift = 0
            self.exception = 0
            self.syscall = 0
            self.ERET = 0
            self.aluOp = 0b0001
            self.upperImmediate = 0

        elif (oppCode == 0b000100): #beq
            self.regDst = 0
            self.aluSrc = 0
            self.memToReg = 0
            self.regWrite = 0
            self.memRead = 0
            self.memWrite = 0
            self.branch = 1
            self.branchne = 0
            self.jump = 0
            self.shift = 0
            self.exception = 0
            self.syscall = 0
            self.ERET = 0
            self.aluOp = 0b0110
            self.upperImmediate = 0
            
        elif (oppCode == 0b000101): #bne
            self.regDst = 0
            self.aluSrc = 0
            self.memToReg = 0
            self.regWrite = 0
            self.memRead = 0
            self.memWrite = 0
            self.branch = 0
            self.branchne = 1
            self.jump = 0
            self.shift = 0
            self.exception = 0
            self.syscall = 0
            self.ERET = 0
            self.aluOp = 0b0110
            self.upperImmediate = 0

        elif (oppCode == 0b100011): #lw
            self.regDst = 0
            self.aluSrc = 1
            self.memToReg = 1
            self.regWrite = 1
            self.memRead = 1
            self.memWrite = 0
            self.branch = 0
            self.branchne = 0
            self.jump = 0
            self.shift = 0
            self.exception = 0
            self.syscall = 0
            self.ERET = 0
            self.aluOp = 0b0010
            self.upperImmediate = 0

        elif (oppCode == 0b101011): #sw
            self.regDst = 0
            self.aluSrc = 1
            self.memToReg = 0
            self.regWrite = 0
            self.memRead = 0
            self.memWrite = 1
            self.branch = 0
            self.branchne = 0
            self.jump = 0
            self.shift = 0
            self.exception = 0
            self.syscall = 0
            self.ERET = 0
            self.aluOp = 0b0010
            self.upperImmediate = 0

        elif (oppCode == 0b010000): #cp0 instructions
            if (function == 0b011000): #ERET: Give control back to users program
                self.regDst = 0
                self.aluSrc = 0
                self.memToReg = 0
                self.regWrite = 0
                self.memRead = 0
                self.memWrite = 0
                self.branch = 0
                self.branchne = 0
                self.jump = 0
                self.shift = 0
                self.exception = 1
                self.syscall = 0
                self.ERET = 1
                self.aluOp = 0
                self.upperImmediate = 0
        else: #nop
            self.regDst = 0
            self.aluSrc = 0
            self.memToReg = 0
            self.regWrite = 0
            self.memRead = 0
            self.memWrite = 0
            self.branch = 0
            self.branchne = 0
            self.jump = 0
            self.shift = 0
            self.exception = 0
            self.syscall = 0
            self.ERET = 0
            self.aluOp = 0
            self.upperImmediate = 0

    def getRegDst(self):
        return self.regDst
    def getAluSrc(self):
        return self.aluSrc
    def getAluOp(self):
        return self.aluOp
    def getMduOp(self):
        return self.mduOp
    def getRegWrite(self):
        return self.regWrite
    def getBranch(self):
        return self.branch
    def getJump(self):
        return self.jump
    def getShift(self):
        return self.shift
    def getMemWrite(self):
        return self.memWrite
    def getMemRead(self):
        return self.memRead
    def getMemToReg(self):
        return self.memToReg
    def getSyscall(self):
        return self.syscall
    def getUpperImmediate(self):
        return self.upperImmediate
    def getMfHiLo(self):
        return self.mfhilo

